/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package se.sll.service.catalogue.composite.camel.processor;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.camel.Exchange;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import se.sll.service.catalogue.composite.data.CodeData;

/**
 *
 * @author khaleddaham
 */
public class CodeProcessor {

    public void codeResponseJSON(Exchange exchange) throws JsonParseException, JsonMappingException, IOException {
        ObjectMapper mapper = new ObjectMapper();
        List<CodeData> responses;
        if (exchange.getIn().getBody(String.class).equals("[]")) {
            responses = new ArrayList<CodeData>();
        } else {
            responses = mapper.readValue(exchange.getIn().getBody(String.class), new TypeReference<List<CodeData>>() {
            });
        }
        exchange.getIn().setBody(responses);
    }
}
